﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.ComponentModel;

namespace ShootSearch.Util
{
    [Serializable]
    [XmlRoot("Assembly")]
    [TypeConverter(typeof(ExpandableConverter<AssemblyConfig>))]
    public class AssemblyConfig
    {
        /// <summary>
        /// Gets or sets the name of the type
        /// </summary>
        [XmlAttribute]
        public string TypeName { get; set; }
        /// <summary>
        /// Gets or sets the assembly of the type
        /// </summary>
        [XmlAttribute]
        public string Assembly { get; set; }
              
        /// <summary>
        /// Constructor Method
        /// </summary>
        public AssemblyConfig() { }
        /// <summary>
        /// Constructor Method with the type
        /// </summary>
        /// <param name="type">the type</param>
        public AssemblyConfig(Type type) 
        {
            TypeName = type.FullName;
            Assembly = AssemblyTools.GetAssemblyFile(type);
        }

        /// <summary>
        /// Gets an instance of the type
        /// </summary>
        /// <returns></returns>
        public object GetObject()
        {
            return AssemblyTools.GetObject(TypeName, Assembly);
        }

        /// <summary>
        /// Returns the type name and assembly
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return TypeName + "," + Assembly;
        }

    
    }

}
